package com.bruce.springai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/chatClient")
@Tag(name = "Ai聊天客户端的controller" , description = "Ai聊天客户端的controller")
public class ChatClientController {

    @Resource
    private ChatClient deepSeekChatClient;
    
    @GetMapping("/chat")
    @Operation(summary = "普通聊天" ,description = "输入message，AI会等到获取全部回答之后，才返回")
    public String chat(@RequestParam(name ="message") String message) {
        return deepSeekChatClient.prompt(message).call().content();
    }
    
    /**
     * 流式输出
     * @param message
     * @return
     */
    @GetMapping(value = "/stream", produces = "text/stream;charset=utf-8")
    @Operation(summary = "流式聊天" ,description = "输入message,Ai流式输出回答")
    public Flux<String> stream(@RequestParam(name ="message") String message) {
        return deepSeekChatClient.prompt(message).stream().content();
    }
    
}
